﻿using CommunityToolkit.Maui.Alerts;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tennis.Models;

namespace Tennis.ViewModels
{
    public partial class HomePageViewModel : BaseViewModel
    {

        private Random random = new Random();
        string[] imgulr = new string[] { "banner.jpg", "slice.png", "https://cdn.pixabay.com/photo/2022/07/21/13/40/mongolian-girl-7336271_960_720.jpg", "http://www.g-pet.cn/Upload/AnLi/ba27bd489b1148dc91f3d3803b8bb12a.jpg", "http://www.g-pet.cn/Upload/AnLi/07c3123b179d416bba6822f2c5c39c11.jpg" };

        Color[] backgroundColors = new Color[] {
            Color.FromRgba(255, 123, 14,40),
             Color.FromRgba(14, 124, 255,40),
              Color.FromRgba(255, 176, 14,40),
               Color.FromRgba(255, 94, 14,40),
                Color.FromRgba(255, 123, 14,40),
        };

        Color[] textColors = new Color[] {
            Color.FromRgb(255, 123, 14),
             Color.FromRgb(14, 124, 255),
              Color.FromRgb(255, 176, 14),
               Color.FromRgb(255, 94, 14),
                Color.FromRgb(255, 123, 14),
        };

        public HomePageViewModel()
        {
            this.Title = "首页";
            this.ProductList = new ObservableCollection<ProductInfo> {


            new  ProductInfo{
                DeletePrice = random.Next(1000, 5000),
                Price = random.Next(100, 1000),
                Description = "很棒加油",
                ImgUrl = imgulr[random.Next(0, imgulr.Length)],
                Title = "产品标题",
                Id = 1,
                BackgroundColor=backgroundColors[1],
                    TextColor=textColors[1],
            },


            new  ProductInfo{
                DeletePrice = random.Next(1000, 5000),
                Price = random.Next(100, 1000),
                Description = "教练讲的很好，也很热情，专业扎实，长得真帅，以后会经常来的",
                ImgUrl = imgulr[random.Next(0, imgulr.Length)],
                Title = "产品标题",
                Id = 2,
                     BackgroundColor=backgroundColors[2],
                    TextColor=textColors[2],
            },

               new  ProductInfo{
                DeletePrice = random.Next(1000, 5000),
                Price = random.Next(100, 1000),
                Description = "教练讲的很好，推荐大家购买",
                ImgUrl = imgulr[random.Next(0, imgulr.Length)],
                Title = "产品标题",
                Id = 1,
              BackgroundColor=backgroundColors[3],
                    TextColor=textColors[3],
            },


            new  ProductInfo{
                DeletePrice = random.Next(1000, 5000),
                Price = random.Next(100, 1000),
                Description = "俱乐部很有逼格，孩子很喜欢这里，每周都会来参加培训，希望再推出更多的优惠活动，给个好评，大家放心过来，教练都有多年的培训经验，都是非常负责任的教练都有多年的培训经验",
                ImgUrl = imgulr[random.Next(0, imgulr.Length)],
                Title = "产品标题",
                Id = 2,
                      BackgroundColor=backgroundColors[4],
                    TextColor=textColors[4],
            },

               new  ProductInfo{
                DeletePrice = random.Next(1000, 5000),
                Price = random.Next(100, 1000),
                Description = "有寒假班吗？双十一活动有吗？",
                ImgUrl = imgulr[random.Next(0, imgulr.Length)],
                Title = "产品标题",
                Id = 1,
                       BackgroundColor=backgroundColors[0],
                    TextColor=textColors[0],
            },


            new  ProductInfo{
                DeletePrice = random.Next(1000, 5000),
                Price = random.Next(100, 1000),
                Description = "真心不错，教练专业有耐心，如果再优惠些会更好哦",
                ImgUrl = imgulr[random.Next(0, imgulr.Length)],
                Title = "产品标题",
                Id = 2,
                   BackgroundColor=backgroundColors[random.Next(0,backgroundColors.Length)],
                 TextColor=textColors[random.Next(0,textColors.Length)],
            },


            };

            this.BannerList = new ObservableCollection<Banner>() {
                  new Banner{Url="banner.jpg" },
              new Banner{Url="banner.jpg" },
                 new Banner{Url="banner.jpg" },
                   new Banner{Url="banner.jpg" },
                      new Banner{Url="banner.jpg" },
                        new Banner{Url="banner.jpg" },
            };
        }
         

        [ObservableProperty]
        private ObservableCollection<ProductInfo> _productList;


        [ObservableProperty]
        private ObservableCollection<Banner> _bannerList;

        #region Commands
        //   [ICommand]

        [ICommand]
        async void GetProductList()
        {


            for (int i = 0; i < 100; i++)
            {
                var index = random.Next(0,textColors.Length);
                this.ProductList.Add(new ProductInfo
                {
                    DeletePrice = random.Next(1000, 5000),
                    Price = random.Next(100, 1000),
                    Description = "我是一段介绍",
                    ImgUrl = imgulr[random.Next(0, imgulr.Length)],
                    Title = "产品标题",
                    Id = ProductList.Count + 1,
                    BackgroundColor = backgroundColors[index],
                    TextColor = textColors[index],
                });
            }

            //this.ProductList.
            await Toast.Make($"加载完成,共{this.ProductList.Count}条数据").Show();

        }

        #endregion

    }
}
